package com.zeta.eduservice.listener;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.zeta.eduservice.entity.excel.QuestionChoiceExcel;
import com.zeta.eduservice.entity.question.ChapterAQuestionTypeSysAndChoicequestion;
import com.zeta.eduservice.entity.question.EduQuestionChoice;
import com.zeta.eduservice.entity.vo.QuestionUploadVo;
import com.zeta.eduservice.service.ChapterAQuestionTypeSysAndChoicequestionService;
import com.zeta.eduservice.service.EduQuestionChoiceService;

public class UploadQuestionChoiceExcelListener extends AnalysisEventListener<QuestionChoiceExcel>{
	EduQuestionChoiceService questionChoiceService;
	ChapterAQuestionTypeSysAndChoicequestionService chapterAQuestionTypeSysAndChoicequestionService;
	QuestionUploadVo uploadVo;
	public UploadQuestionChoiceExcelListener(ChapterAQuestionTypeSysAndChoicequestionService chapterAQuestionTypeSysAndChoicequestionService,EduQuestionChoiceService questionChoiceService,QuestionUploadVo questionUploadVo){
		this.questionChoiceService=questionChoiceService;
		this.uploadVo=questionUploadVo;
		this.chapterAQuestionTypeSysAndChoicequestionService=chapterAQuestionTypeSysAndChoicequestionService;
	}
	@Override
	public void invoke(QuestionChoiceExcel data, AnalysisContext context) {
		// TODO Auto-generated method stub
		EduQuestionChoice eduQuestionChoice = new EduQuestionChoice();
		BeanUtils.copyProperties(data, eduQuestionChoice);
//		eduQuestionChoice.setChapterId(chapterId);
		questionChoiceService.save(eduQuestionChoice);
	ChapterAQuestionTypeSysAndChoicequestion chapterAQuestionTypeSysAndChoicequestion = new ChapterAQuestionTypeSysAndChoicequestion();
	chapterAQuestionTypeSysAndChoicequestion.setQuestionId(eduQuestionChoice.getId()).setRegistId(uploadVo.getTypeId());
	chapterAQuestionTypeSysAndChoicequestionService.save(chapterAQuestionTypeSysAndChoicequestion);
	}

	@Override
	public void doAfterAllAnalysed(AnalysisContext context) {
	
	}

}
